<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/boot.js"></script>
    <style>
        #file {
            display: inline-block;
            vertical-align: middle;
            height: 38px;
            line-height: 38px;
            margin-left: 5px;
        }
    </style>
</head>

<body>
    <div id="container">
        <div id="formcontainer">
            <form class="layui-form layui-form-pane" id="editform" lay-filter="editform">
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">分组标识</label>
                            <div class="layui-input-block">
                                <input type="text" name="group_guid" id="group_guid" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" pane="">
                            <label class="layui-form-label required">分类标识</label>
                            <div class="layui-input-block">
                                <input type="text" name="group_type" id="group_type" autocomplete="off" class="layui-input required" value="default">
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-xs12">
                            <div class="layui-form-item" pane="">
                                <label class="layui-form-label required">文件</label>
                                <div class="layui-input-block">
                                    <input type="file" name="file" id="file" />
                                </div>
                            </div>
                        </div>
                    </div>
            </form>
        </div>
        <div id="opcontainer">
            <button class="layui-btn" onclick="HandleSave()">上传</button>
            <button class="layui-btn layui-btn-primary" onclick="HandleClose()">关闭</button>
        </div>
    </div>
</body>
<script>
    $(function() {

    })

    function HandleSave() {
        var formvalidator = $("#editform").validate();
        if (formvalidator.form()) {
            var file = document.getElementById("file").files[0];
            if (!file) {
                OpenFailMessage("请选择需要上传的文件");
                return;
            }
            var formData = new FormData();
            var file = document.getElementById("file").files[0];
            formData.append("file", file, file.name);
            formData.append("group_guid", $("#group_guid").val());
            formData.append("group_type", $("#group_type").val());
            HttpForm(formData, "system/common/attach/upload", function(result, status) {
                if (result.code == 0) {
                    OpenSuccess('上传成功', function(params) {
                        CloseDialog();
                    })
                } else {
                    OpenFail(result.msg);
                }
            })
        }

    }

    function BeforeSubmit(data) {
        return true;
    }

    function HandleClose() {
        CloseDialog();
    }
</script>

</html>